package com.dao.impl;

import com.dao.CarouselFigureDao;
import com.pojo.CarouselFigure;
import com.pojo.Users;
import com.utils.JDBCUtil;

import java.util.List;

public class CarouselFigureDaoImpl implements CarouselFigureDao {
    @Override
    public List<CarouselFigure> findAll(int start,int limit) {
        return JDBCUtil.queryList(CarouselFigure.class,"select * from s_carousel_figure limit ?,?",start,limit);
    }

    @Override
    public int selectCount() {
        return JDBCUtil.queryCount("select count(*) from s_carousel_figure");
    }

    /**
     * 获取最大的序号
     * @return
     */
    @Override
    public int findMaxSerialNumber() {
        return JDBCUtil.queryCount("select max(sequence_num) from s_carousel_figure");
    }

    /**
     * 添加方法
     * @param carouselFigure
     * @return
     */
    @Override
    public int addCF(CarouselFigure carouselFigure) {
        return JDBCUtil.update("insert into s_carousel_figure values(?,?,?)",carouselFigure.getId(),carouselFigure.getUrl(),carouselFigure.getSequenceNum());
    }

    /**
     * 删除方法
     * @param id
     * @return
     */
    @Override
    public int deleteCF(String id) {
        return JDBCUtil.update("CALL deleteFC(?);",id);
    }

    /**
     * 根据ID获取到指定元素
     * @param id
     * @return
     */
    @Override
    public CarouselFigure findByID(String id) {
        return JDBCUtil.queryOne(CarouselFigure.class,"select * from s_carousel_figure where id = ?",id);
    }

    /**
     * 根据序号获取一条数据
     * @param SequenceNum
     * @return
     */
    @Override
    public CarouselFigure findBySequenceNum(Integer SequenceNum) {
        System.out.println("第n次"+SequenceNum);
        return JDBCUtil.queryOne(CarouselFigure.class,"select * from s_carousel_figure where sequence_num = ?",SequenceNum);
    }

    /**
     * 修改方法
     * @param carouselFigure
     * @return
     */
    @Override
    public int updateCF(CarouselFigure carouselFigure) {

        return JDBCUtil.update("update s_carousel_figure set url = ?,sequence_num=? where id = ?",carouselFigure.getUrl(),carouselFigure.getSequenceNum(),carouselFigure.getId());
    }
}
